﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using WF_QLThuVien.BusinessLayer.PhieuMuon;

namespace WF_QLThuVien.PresentationLayer
{
    public partial class FormTimKiemPhieuMuon : Form
    {
        #region: Delegate
        public delegate void UpdateTimPM(ArrayList arrPhieuMuon, string trangThaiTim);
        public event UpdateTimPM UpdateTimPM_Click;
        #endregion

        #region: Khai báo biến
        CPhieuMuonBLL GPhieuMuonBLL = new CPhieuMuonBLL();
        #endregion

        public FormTimKiemPhieuMuon()
        {
            InitializeComponent();
        }

        private void rdbTimChinhXac_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbTimChinhXac.Checked)
            {
                gbTimChinhXac.Enabled = true;
                gbTimGanDung.Enabled = false;
            }
            else
            {
                gbTimChinhXac.Enabled = false;
                gbTimGanDung.Enabled = true;
                chkTenSach_CheckedChanged(sender, e);
                chkTenDocGia_CheckedChanged(sender, e);
                chkNgayLapPhieu_CheckedChanged(sender, e);
            }
        }

        private void FormTimKiemPhieuMuon_Load(object sender, EventArgs e)
        {
            rdbTimChinhXac_CheckedChanged(sender, e);

        }

        private void txtTimChinhXac_TextChanged(object sender, EventArgs e)
        {
          
        }

        private void rdbTimGanDung_CheckedChanged(object sender, EventArgs e)
        {
          
        }

        private void chkNgayLapPhieu_CheckedChanged(object sender, EventArgs e)
        {
            if (chkNgayLapPhieu.Checked)
            {
                dtpNgayLap.Enabled = true;
            }
            else
            {
                dtpNgayLap.Enabled = false;
            }
        }

        private void chkTenDocGia_CheckedChanged(object sender, EventArgs e)
        {
            if (chkTenDocGia.Checked)
            {
                txtTenDocGia.Enabled = true;
            }
            else
            {
                txtTenDocGia.Enabled = false;
            }
        }

        private void chkTenSach_CheckedChanged(object sender, EventArgs e)
        {
            if (chkTenSach.Checked)
            {
                txtTenSach.Enabled = true;
            }
            else
            {
                txtTenSach.Enabled = false;
            }
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (rdbTimChinhXac.Checked == true)
            {
                if (rdbMaDocGia.Checked == true)
                {
                    string maDocGia = txtTimChinhXac.Text;
                    UpdateTimPM_Click(GPhieuMuonBLL.LoadOnlyPMByMaDocGia(maDocGia), maDocGia);
                    this.Dispose();
                }
                else //rdbMaSach
                {
                    string maSach = txtTimChinhXac.Text;
                    UpdateTimPM_Click(GPhieuMuonBLL.LoadOnlyPMByMaSach(maSach), maSach);
                    this.Dispose();
                }
            }
        }
    }
}
